require 'socket'

##################################
#
# These functions are commands to send various
# instuctions/messages to the irc server
#
#################################

class Squick

  # push msg blindly at the IRC server
  def say(msg)
    @socket.puts msg
  end

  # try to join channel
  def join(channel)
    say "JOIN #{channel}"
    @channel = channel      #Note that it's in a channel now
  end

  # request a list of who is in @channel
  def getNameList()
    say("NAMES #{@channel}")
  end

  # Initialize the user nick on the server
  def initializeIrcConnection(nick)
    say "NICK #{nick}"
    say "USER nrasput 0 * Nick_Rasputin"
  end

  # send a PM to nick containing msg
  def sayToUser(nick, msg)
    print(%x{date}.chop)
    puts("\t\e[1;31m#{@nick} (to #{nick})\e[0m: #{msg}")
    @socket.puts "PRIVMSG #{nick} :#{msg}"
  end

  #broadcast msg to the whole channel
  def sayToChan(msg)
        print(%x{date}.chop)
        puts("\t\e[1;31m#{@nick}\e[0m: #{msg}")
    @socket.puts "PRIVMSG #{@channel} :#{msg}"
  end

  # respond to server's PINGS to not timeout
  def handleKeepAlive(msg)
    if msg.match(/^PING :(.*)$/) then
      say "PONG #{$~[1]}"
      return true
    end
    return false
  end

  # Request that nick be made an op in the channel
  def elevateToOp(nick)
    say "MODE #{@channel} +o #{nick}"	
  end 

end
